<style scoped>
.layui-row {
    overflow: hidden;
}

.select-item {
    width: 34.333333%;
    float: right;
}

.layui-row:after,
.layui-row:before {
    clear: none;
}

.layui-row {
    overflow: hidden;
}

.select-item {
    width: 34.333333%;
    float: right;
}

.layui-row:after,
.layui-row:before {
    clear: none;
}
</style>

<template>
<div class="salesSpecification">
    <div>
        <a href="javascript:;" class="layui-btn" @click="add"><i class="layui-icon">&#xe654;</i>添加产品套装</a>
    </div>

    <form class="layui-form ">
        <div class="layui-col-lg4 select-item" style="text-align: right;width: auto">

            <div class="layui-inline" style="width: 160px">

                <select v-model="category" name="category" id="category" lay-filter="category" placeholder="请选择" class="layui-form-select">
                    <option value="">请选择套装</option>
                </select>
            </div>
            <!-- <div class="layui-inline" style="width: 160px">

                <select v-model="brand" name="brand" id="brand" lay-filter="brand" placeholder="请选择" class="layui-form-select">
                    <option value="">请选择单品</option>
                </select>
            </div> -->
            <button type="button" class="layui-btn sou" @click="search">搜索</button>
        </div>

    </form>

    <table class="layui-table layui-form">

        <thead>
            <tr>
                <th>套装名称</th>
                <th>产品名称</th>
                <th>数量</th>
                <th>单价</th>
                <th>创建人</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <tr class="id9" v-for="(val, index) in departments" :key="index">
                <th>{{val.suitpack}}</th>
                <th>{{val.product}}</th>
                <th>{{val.amount}}</th>
                <th>{{val.price}}</th>
                <th>{{val.operator}}</th>
                <th>{{val.createtime}}</th>
                <th><a href="javascript:;" @click="del(val.guid)">删除</a></th>
            </tr>
        </tbody>
    </table>

    <Pagination :cur="currentPage" :all="totalPage" :callback="turnPage"></Pagination>
    <div style="height: 200px"></div>
</div>
</template>

<script>
import Pagination from '../common/Pagination.vue'
export default {
    name: 'SalesSpecification',
    components: {
        Pagination
    },
    data() {
        return {
            departments: [],
            currentPage: 1,
            totalPage: 0,
            searchName: '',
            products: '',
            category: '',
            brand: '',
            name: ''
        }
    },
    mounted() {
        let that = this;
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;
            that.getPageData();
            that.getBaseInfo();
            that.getBaseInfo1();

        });

    },
    methods: {
        search: function () {
            this.getPageData('search');
        },
        turnPage: function (data) {
            this.currentPage = data;
            this.getPageData();
        },
        getPageData: function (type = '') {
            let that = this;
            let loader = layui.layer.load();

            let postData = {
                'entity.suitSpid': $('#category').val(),
                'entity.childSpid': $('#brand').val(),
                productGuid: that.products,
                stat:$('#status').val(),
                searchName:that.searchName
            }
            if (type != 'search') {
                postData.pageNo = that.currentPage;
            } else {
                postData.pageNo = 1;
            }

            $.ajax({
                url: '/sales/Suitpack!page.action',
                type: "post",
                data: postData,
                dataType: "json",
                success: function (res) {
                    if (res.msg == 'success') {
                        that.totalPage = res.pagelist.pageCount;
                        that.departments = res.pagelist.rows;
                    } else {
                        that.alert("系统错误");
                    }
                },
                complete: function () {
                    layer.close(loader);
                }
            });
        },
        add: function () {
            this.$parent.switchPage('addSuitPack');
        },
        edit: function (id) {
            this.$parent.guids = id;
            this.$parent.switchPage('editSuitPack');
        },
        del: function (id, likeCode) {
            let that = this;

            layer.confirm('确定要删除该数据？', function () {
                let loader = layer.load();
                $.ajax({
                    url: '/sales/Suitpack!del.action',
                    type: "post",
                    data: {
                        suitpackid: id
                    },
                    dataType: "json",
                    success: function (res) {
                        var result = res.info;
                        if (result != "fail") {
                            that.toast("删除成功");
                            that.getPageData();
                        } else {
                            console.log(result)
                            that.toast(res.errorMsg);
                        }
                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });
            })
        },
        getBaseInfo: function (type = '') {
            let params = {
                'entity.flag': 2
            }
            $.ajax({
                url: '/sales/Salesspecification!getSpecification.action',
                type: "post",
                dataType: "json",
                data: params,
                success: function (res) {
                    if (res.msg == "success") {
                        $.each(res.spes, function (index, item) {
                            $('#category').append(new Option(item.name, item.guid));
                            layui.form.render("select");
                        });
                    } else {
                        that.alert("系统错误");
                    }

                }
            });
        },
        getBaseInfo1: function (type = '') {
            let params = {
                'entity.flag': 1,
                'entity.type': 2
            }
            $.ajax({
                url: '/sales/Salesspecification!getSpecification.action',
                type: "post",
                dataType: "json",
                data: params,
                success: function (res) {
                    if (res.msg == "success") {
                        $.each(res.spes, function (index, item) {
                            $('#brand').append(new Option(item.name, item.guid));
                            layui.form.render("select");
                        });
                    } else {
                        that.alert("系统错误");
                    }

                }
            });
        }
    }
}
</script>
